<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>课程列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
		<link rel="stylesheet" href="/static/css/public.css" media="all">
	</head>
	<body>
		<div class="layuimini-container">
			<div class="layuimini-main">

				<fieldset class="table-search-fieldset">
					<legend>搜索信息</legend>
					<div style="margin: 10px 10px 10px 10px">
						<form class="layui-form layui-form-pane" action="">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">订单编号</label>
									<div class="layui-input-inline">
										<input type="text" name="order_id" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">交易流水号</label>
									<div class="layui-input-inline">
										<input type="text" name="trade_no" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">用户名称</label>
									<div class="layui-input-inline">
										<input type="text" name="user_name" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">课程编号</label>
									<div class="layui-input-inline">
										<input type="text" name="course_id" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<button type="submit" class="layui-btn layui-btn-primary" lay-submit
										lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
								</div>
							</div>
						</form>
					</div>
				</fieldset>

				<table class="layui-hide" id="orderTable" lay-filter="currentTableFilter"></table>

				<script type="text/html" id="currentTableBar">
					<!-- <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a> -->
				<!-- <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="set_panshare">网盘链接</a> -->
				<!-- <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a> -->
				</script>

			</div>
		</div>
		<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
		<script>
			function getCookie(name) {
				var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
				return r ? r[1] : undefined;
			}


			layui.use(['form', 'table'], function() {
				var $ = layui.jquery,
					form = layui.form,
					table = layui.table;

				// 获取课程列表
				var course_list;
				var course_data = {
					"curr": 1,
					"nums": 10,
					"searchParams": {
						"course_id": "",
						"course_title": "",
						"label_id": "",
						"contents_id": ""
					}
				};
				$.ajax({
					type: "post", //get或者post
					contentType: 'application/json',
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/course_list',
					data: JSON.stringify(course_data), //参数 接口传参 json对象
					success: function(res) {
						course_list = res.data;
					}
				})

				// 获取用户列表
				var user_list;
				var user_data = {
					"curr": 1,
					"nums": 10,
					"searchParams": {
						"user_id": "",
						"user_name": "",
						"mail": ""
					}
				};
				$.ajax({
					type: "post", //get或者post
					contentType: 'application/json',
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/user_list',
					data: JSON.stringify(user_data), //参数 接口传参 json对象
					success: function(res) {
						user_list = res.data;
					}
				})



				// 请求列表数据
				let order_data = {
					"order_id": "",
					"trade_no": "",
					"user_name": "",
					"course_id": ""
				}
				var title;
				var user_name;
				table.render({
					elem: '#orderTable',
					toolbar: '#toolbarDemo',
					method: 'post',
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/orders/listAll',
					contentType: 'application/json',
					request: {
						pageName: 'curr', //页码的参数名称，默认：page
						limitName: 'nums' //每页数据量的参数名，默认：limit
					},
					where: {
						searchParams: order_data
					},
					cols: [
						[{
								type: "checkbox",
								width: 50
							},
							{
								type: 'numbers'
							},
							{
								field: 'order_id',
								width: 150,
								title: '订单编号',
								sort: true
							},
							{
								field: 'trade_no',
								width: 200,
								title: '交易流水号'
							},
							{
								field: 'course_title',
								width: 200,
								title: '课程标题',
								templet: function(date) {
									$.each(course_list, function(index, value) {
										if (date.course_id == value.course_id) {
											course_title = value.title
										};
									});
									return course_title;

								}
							},
							{
								field: 'user_name',
								width: 150,
								title: '用户名称',
								templet: function(date) {
									$.each(user_list, function(index, value) {
										if (date.user_id == value.user_id) {
											user_name = value.user_name
										};
									});
									return user_name;

								}
							},
							{
								field: 'order_price',
								width: 150,
								title: '订单价格'
							},
							{
								field: 'order_status',
								width: 100,
								title: '订单状态',
								templet: function(data) {
									return data.order_status == 2 ? "已完成" : "已取消"
								}
							},
							{
								field: 'create_time',
								width: 200,
								title: '创建时间'
							},
							{
								title: '操作',
								minWidth: 60,
								toolbar: '#currentTableBar',
								align: "center"
							}
						]
					],
					limits: [10, 15, 20, 25, 50, 100],
					limit: 10,
					groups: 3,
					page: true,
					skin: 'line'
				});

				// 监听搜索操作
				form.on('submit(data-search-btn)', function(searchinfo) {
					order_data["order_id"] = searchinfo.field.order_id
					order_data["trade_no"] = searchinfo.field.trade_no
					order_data["user_name"] = searchinfo.field.user_name
					order_data["course_id"] = searchinfo.field.course_id
					//执行搜索重载
					table.reload('orderTable', {
						contentType: 'application/json',
						request: {
							pageName: 'curr', //页码的参数名称，默认：page
							limitName: 'nums' //每页数据量的参数名，默认：limit
						},
						where: {
							searchParams: order_data
						},
					});

					return false;
				});

				//监听表格复选框选择
				table.on('checkbox(currentTableFilter)', function(obj) {
					console.log(obj)
				});



			});
		</script>

	</body>
</html>
